-----------------------------------
-- Area: Dragons Aery
-- HNM: Nidhogg
-- @zone 154
-- @pos 78.000 6.000 34.000
-----------------------------------

require("scripts/globals/settings");
require("scripts/globals/titles");
require("scripts/globals/status");

-----------------------------------
-- onMobInitialize Action
-----------------------------------

function onMobInitialize(mob)
end;

-----------------------------------
-- onMobFight Action
-----------------------------------

function onMobFight(mob, target)
    local battletime = mob:getBattleTime();
    if (mob:getExtraVar(1) == 0) then
        mob:setExtraVar(math.random(30,90));
    end
    if (battletime >= mob:getExtraVar(1)) then
        mob:useMobAbility(700); -- Technically Aerial Hurricane wing, but I'm using 700 for his two hour (since I have no inclination to spend millions on a PI to cap one name you never see)
        mob:setExtraVar(battletime + math.random(60,120));
    end
end;

-----------------------------------
-- onMobDeath
-----------------------------------

function onMobDeath(mob, killer)

    killer:addTitle(NIDHOGG_SLAYER);

    -- Set Nidhogg's Window Open Time
    if (LandKingSystem_HQ == 0 or LandKingSystem_HQ == 2) then
        local wait = 72 * 3600
        SetServerVariable("[POP]Nidhogg", os.time(t) + (wait /HNM_TIMER_MOD)); -- 3 days
        DeterMob(mob:getID(), true);
    end

    -- Set Fafnir's spawnpoint and respawn time (21-24 hours)
    if (LandKingSystem_NQ == 0 or LandKingSystem_NQ == 2) then
        local Fafnir = 17408018;
        SetServerVariable("[PH]Nidhogg", 0);
        DeterMob(Fafnir, false);
        UpdateNMSpawnPoint(Fafnir);
        GetMobByID(Fafnir):setRespawnTime((math.random((75600),(86400))) /HNM_TIMER_MOD);
    end
end;